package com.chilli.cosima.data.dao.impl;

import java.util.List;

import com.chilli.cosima.data.BaseHibernateDAO;
import com.chilli.cosima.data.bean.TOperator;
import com.chilli.cosima.data.bean.TPower;
import com.chilli.cosima.data.dao.LoginDAO;
import com.chilli.cosima.data.jdbc.DbTools;

public class LoginDAOImpl extends BaseHibernateDAO implements LoginDAO
{

	@SuppressWarnings("unchecked")
	public List<TPower> findChildrenPowerByParentId(String powerid)
	{
		StringBuffer queryhql = new StringBuffer();
		queryhql.append("from TPower t where t.fatherid='" + powerid
				+ "' and t.isbutton=1");
		List<TPower> powerlist = this.findObjectByHQL(queryhql.toString());
		return powerlist;
	}

	public List<String> findPowerIdListWithoutButton(TOperator operator)
	{
		StringBuilder sb = new StringBuilder();
		sb
				.append(
						"select t1.powerid from T_POWER_ROLE t1, T_POWER t2 where t1.roleid=")
				.append(operator.getRoleid()).append(
						" and t1.powerid=t2.powerid and t2.isbutton=1");
		List<String> list = DbTools.selectCol(sb.toString());
		return list;
	}

	public List<String> findPowerIdListWithButton(TOperator operator)
	{
		StringBuilder sb = new StringBuilder();
		sb
				.append(
						"select t1.powerid from T_POWER_ROLE t1, T_POWER t2 where t1.roleid=")
				.append(operator.getRoleid()).append(
						" and t1.powerid=t2.powerid");
		List<String> list = DbTools.selectCol(sb.toString());
		return list;
	}

	public List<String> findPowerUrlListWithButton(TOperator operator)
	{
		StringBuilder sb = new StringBuilder();
		sb
				.append(
						"select t2.powerurl from T_POWER_ROLE t1, T_POWER t2 where t1.roleid=")
				.append(operator.getRoleid()).append(
						" and t1.powerid=t2.powerid");
		List<String> list = DbTools.selectCol(sb.toString());
		return list;
	}
}
